/*
ECS386: Introduction to embedded systems
Spirometer Group
Members:
1) Keerati Suibkitwanchai ID:5422780395
2) Siwalee Choilek ID:5422780536
*/

///////////////////////////////Pressure Measure////////////////////////////////////////////////////

const int pressurePin = A0;           //pin AO is connected to output voltage

void setup(){ 
  Serial.begin(9600);                 //begin serial communication with baud rate 9600.
  pinMode(pressurePin, INPUT);        //set the pressure pin as an input.
}

void loop(){ 
  float inputValue = analogRead(pressurePin); //read the input value from the pressure pin (analog from 0 to 1023).
  float voltage = (inputValue/1024.0)*5.0;    //convert the input value to voltage ranged from 0 to 5 volt.
  float pressure = (voltage/5.0)*10000.0;     //convert the voltage to the differential pressure ranged from 0 to 10 kPa (sensor MPXV5010DP)
  
  //To observe the difference of the pressure, we use | to see the difference
  if(pressure<460){
    Serial.println("|||||");
  }  
  else if(pressure>460&&pressure<500){
    Serial.println("||||||||||");
  }
  else if(pressure>=500&&pressure<550){
    Serial.println("|||||||||||||||");
  }
  else if(pressure>=550&&pressure<600){
    Serial.println("||||||||||||||||||||");
  }
  else if(pressure>=600&&pressure<650){
    Serial.println("||||||||||||||||||||||||||");
  }
  else if(pressure>=650&&pressure<700){
    Serial.println("||||||||||||||||||||||||||||||||");
  }
  else if(pressure>=700&&pressure<750){
    Serial.println("|||||||||||||||||||||||||||||||||||||");
  }
  else{
    Serial.println("|||||||||||||||||||||||||||||||||||||||||");
  }
  
  delay(20); //delay in every 20 milliseconds
}
